﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@page import="global.Constants"%>
<%@page import="com.aiflow.Action.DictionaryAction"%>

<%@page import="com.aiflow.Action.DepartmentAction"%>
<html>
<head>
	<%
		String baseUrl = request.getContextPath();
	%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
	    //这里的全局是为了修改之后的刷新
	    var userConfListGrid;
		$(document).ready(function(){
		    //角色勾选的变量
		    var checkid;
		    var checktext;
		    //部门的变量
		    var deptid;
		    var depttext;
			// 全局参数
			var baseParams = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			var EXT_QUERY_TIME_OUT = 1200000;
     
			// 传报数据源  userName,u.telep ,d.name as targetName
		    var userConfListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/userConf_findUserConfig.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        totalProperty: 'results',
		        fields: ['id','userName','telep','targetName','dept_name','spec'],
		        baseParams: baseParams,
		        autoLoad: true,
				listeners : {  
          load : function() {  
              isDetailReady = true;// 查询置换标志为已查过   
            }  
            }  
		    });
			
		
		
				   	    // 工具栏
		    var userConfListToolbar = new Ext.Toolbar({
		    	renderTo: 'userConfListToolBarDiv',
		    	items: [
					new Ext.Button({
					    id: 'userConfList-add-button',
					    text: '添加',
						iconCls: 'user_add'
						//disabled:true
					}),
					new Ext.Button({
					    id: 'userConfList-update-button',
					    text: '编辑',
						iconCls: 'user_edit'
					}),
					new Ext.Button({
					    id: 'userConfList-delete-button',
					    text: '删除',
						iconCls: 'status_busy'
					}),
					'-',
		            new Ext.ux.form.SearchField({
		                store: userConfListStore,
		                width: 320,
		                paramName: 'userName',
		                emptyText: '请输入传报人员名称',
		                style: 'margin-left: 10px;'
		            })
				]
			});
 
			// 数据表格    dept_name spec
			var sm = new Ext.grid.CheckboxSelectionModel();
			userConfListGrid = new Ext.grid.GridPanel({
				id: 'userConfListGrid',
				renderTo: 'userConfListGridDiv',
				border: false,
				stateful: true,
			    autoScroll: 'auto',
		        store: userConfListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [
						sm,
						new Ext.grid.RowNumberer({header:'№',width:50}),
						{id:'id',header: '姓名', width: 150, hidden: true, sortable: true, dataIndex: 'id'},
						{id:'userName',header: '姓名', width: 150, hidden: false, sortable: true, dataIndex: 'userName'},
			            {id:'telep',header: '电话', width: 100,hidden: false, sortable: true, dataIndex: 'telep'},
			            {id:'targetName',header: '传报对象', width: 200,hidden: false, sortable: true, dataIndex: 'targetName'},
			            {id:'dept_name',header: '部门', width: 200,hidden: false, sortable: true, dataIndex: 'dept_name'},
			            {id:'spec',header: '专业', width: 200,hidden: false, sortable: true, dataIndex: 'spec'}
			            		
			             	         					]
		        }),
		        sm: sm,
		        columnLines: true,
		         bbar: new Ext.PagingToolbar({
					pageSize: <%=Constants.PAGE_SIZE %>,
					store: userConfListStore,
					displayInfo: true,
					displayMsg: Anynote.PAGINGTOOLBAR_DISPLAYMSG,
					emptyMsg: Anynote.PAGINGTOOLBAR_EMPTYMSG,
					doLoad: function(start){
						baseParams.start = start;
						this.store.load({params: baseParams});
					}
		        })
		      
		    });
			// 设置Grid高度和宽度
			 Anynote.resizeGridTo("userConfListGrid", 0, 56);
		
             $("#userConfList-add-button").click(function(){ //////////////////////
			  	// 传报对象 数据源
	        var alarmStore = new Ext.data.ArrayStore({  
	            fields : ['alarm_id', 'alarm_name'],  
	            data : <%=DictionaryAction.getDictionaryCombo("76")%>,
	            sortInfo: {field: "alarm_id", direction: "ASC"}
	        });
	        
	         // 区域  数据源  getDepartmentCombo
	         var regionStore = new Ext.data.ArrayStore({  
	            fields : ['region_id', 'region_name'],  
	            data : <%=DepartmentAction.getDepartmentCombo("")%>,
	            sortInfo: {field: "region_id", direction: "ASC"}
	        });
	        
	           var specialtyStore = new Ext.data.ArrayStore({  
	            fields : ['specialty_id', 'specialty_name'],  
	            data : <%=DictionaryAction.getDictionaryCombo("98")%>,
	            sortInfo: {field: "specialty_id", direction: "ASC"}
	        });
			 
		     				// 新增人员设置Form
				var addUserConfFormPanel = new Ext.FormPanel({
					id: 'addUserConfFormPanel',
			        labelWidth: 60,
			        buttonAlign: 'center',
			        border: false,
			        bodyStyle: 'padding:10px;text-align:left;background-color:transparent;',
			        url: '',
		            items:[{//   人员姓名
			                xtype:'textfield',
			                name: 'user_name',
			                fieldLabel: '姓名',
			                anchor:'98%',
			                allowBlank:false,
			                maxLength: 20
			           },{//    手机号
			                xtype:'textfield',
			                name: 'telep',
			                fieldLabel: '手机号码',
			                anchor:'98%',
			            //     regex: /^1[\d]{10}$/,
                            regexText: '手机号码必须1开头,后面跟10位数字！',
                            allowBlank:false,
			                maxLength: 20
			           },{  
			                xtype:'combo',
			                hiddenName: 'alarmTarget',
			                fieldLabel: '传报对象',
			                store: alarmStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'alarm_id',
			                displayField: 'alarm_name',
			                allowBlank:false,
			                editable: false,
			                width: 230,
			                anchor:'98%'
			           },{  
			                xtype:'combo',
			                hiddenName: 'region',
			                fieldLabel: '所属省市',
			                store: regionStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'region_id',
			                displayField: 'region_name',
			                allowBlank:false,
			                editable: false,
			                width: 230,
			                anchor:'98%'
			           },{  
			                xtype:'combo',
			                hiddenName: 'specialty',
			                fieldLabel: '专业',
			                store: specialtyStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'specialty_id',
			                displayField: 'specialty_name',
			                allowBlank:false,
			                editable: false,
			                width: 230,
			                anchor:'98%'
			           },{//   描叙
			                xtype:'textarea',
			                id: 'describe',
			                name: 'describe',
			                fieldLabel:'描叙',
			                width: 230,
			                anchor:'98%'
			              
		                }],
			        buttons: [{
	                    text:'提交',
	                    handler: function(){
	                      
				        	var form = addUserConfFormPanel.getForm();
						    if(form.isValid()){
						     //    form.findField('rolename').setValue(checktext.toString());
						    	// 发送请求
								Anynote.ajaxRequest({
								 
									 baseParams: form.getValues(),
									action: '${pageContext.request.contextPath}/userConf_adduserConfig.action',
									callback: function(jsonResult){
										userConfListGrid.getStore().reload();
										addUserConfWindow.close();
									},
									showWaiting: true,
									failureMsg: '保存失败.'
								});
							}
	                	}
	                },{
	                    text: '重置',
	                    handler: function(){
	                		addUserConfFormPanel.getForm().reset();
	                    }
	                }]
			    });
				// 新增人员 配置 窗口
				var addUserConfWindow = new Ext.Window({
					title: '添加传报人员',
					width: 330,
					height: 320,
					modal: true,
					maximizable: false,
					resizable: false,
					layout:'fit',
					iconCls: 'user_add',
					plain: true,
					items: [addUserConfFormPanel]
				}).show();
			
          })
           
            
            
            // 启用编辑 
			$("#userConfList-update-button").click(function(){
				// 启用
				submit("update");
			});

			// 删除按钮
			$("#userConfList-delete-button").click(function(){
				// 提交
				submit("delete");
			});

			// 提交
			function submit(type){
				var msg = "";
				var status = 0;
				if(type=="delete"){
				    status = 1;
					msg = "确定要删除该传报吗？";
				}else if(type=="update"){
				    status = 2;
				}
				var records = userConfListGrid.getSelectionModel().getSelections();
				
				if(records.length < 1){
					 Ext.Msg.alert("提示", "请至少选择一条数据.");
				}else{
					   //如果点击的是删除
					   if(status == 1){
					      Ext.Msg.confirm("警告", msg, function(btn){
						  if(btn=="yes"){
							var userConfIds = "";
							for(var i=0;i<records.length;i++){
								userConfIds = userConfIds + records[i].get("id") + ",";
							}
							// 发送请求
							
							Anynote.ajaxRequest({
								baseUrl: '<%=baseUrl %>',
							       baseParams: {userConfIds:userConfIds },
								action: '${pageContext.request.contextPath}/userConf_deleteUserConfig.action',
								callback: function(jsonResult){
									userConfListGrid.getStore().reload();
								},
								showWaiting: true,
								failureMsg: '保存失败.'
							});
						   }
					     });
					   //如果点击的是编辑传报
					   }else if(status == 2){
					        var userConfIds = "";
						    userConfIds = records[0].get("id");
						     
					        //只能一条一条的编辑，不能多个一起编辑
					        if(records.length == 1){
						        editUserConfWindow = new Ext.Window({
								title: '编辑传报人员',
								width: 330,
								height: 330,
								modal: true,
								maximizable: false,
								resizable: false,
								layout:'fit',
								plain: true,
								iconCls: 'user_edit',
								autoLoad:{url:'${pageContext.request.contextPath}/page/bussmodule/conscientious/editCons.jsp?userConf='+userConfIds,scripts:true,nocache:true},
								listeners: {
									close: function(){
										
									}
								}
								});
								editUserConfWindow.show();
					        }else{
					            Ext.Msg.alert("提示", "只能选择一条数据.");
					        }
					   }
					}
			}
 });

	</script>
</head>
<body>
<div id="userConfListDiv">
	<div id="userConfListToolBarDiv"></div>
	<div id="userConfListGridDiv" style="width:100%;height:100%;"></div>
</div>

</body>
</html>
